<?php
namespace Admin\Controller;
//use Common\Controller\PublicController;

class FeedbackController extends \Home\Controller\PublicController{
	public function index(){
		$id = $_SESSION["admin_id"];
		$type = $_POST["option"];
		$key = $_POST["where"];
		if($key == NULL){
			$sql = "select a.id,a.content,a.feedbacktime,b.nickname from think_feedback as a,think_user as b where a.uid=b.uid and a.uid={$id} and a.type=0 order by feedbacktime desc";
			$back = M()->query($sql);
		}else{
			$sql = "select * from think_feedback as a,think_user as b where a.uid=b.uid and a.uid={$id} and {$type} like '%{$key}%' and a.type=0 order by feedbacktime desc";
			$back = M()->query($sql);
		}

		$this->assign("type",$type);
		$this->assign("key",$key);
		$this->assign("back",$back);
		$this->display();
	}
	public function select(){
		$type = $_GET["type"];
		$id = $_GET["id"];

			$sql = "select a.id,a.content,a.feedbacktime,b.nickname from think_feedback as a,think_user as b where a.uid=b.uid and a.id={$id} ";
			$sele = M()->query($sql);

		$this->assign("type",$type);
		$this->assign("sele",$sele[0]);
		$this->display();
	}
	public function adopt(){
		$id = $_GET["id"];
		//$date =date('y-m-d h:i:s');
		$adopt = M("feedback")->where("id={$id}")->save(array(
									"type"=>1,
									"time"=>date('y-m-d H:i:s')
						));
		if($adopt > 0){
			$this->redirect('index');
			exit;
		}
	}
	
	public function reject(){
		$id = $_GET["id"];
		$adopt = M("feedback")->where("id={$id}")->save(array(
				"type"=>2,
				"time"=>date('y-m-d H:i:s')
		));
		if($adopt > 0){
			$this->redirect('index');
			exit;
		}
	}
	
	public function handle(){
		$id = $_SESSION["admin_id"];
		$type = $_POST["option"];
		$key = $_POST["where"];
		if($key == NULL){
			$sql = "select a.id,a.type,a.time,a.content,a.feedbacktime,b.nickname from think_feedback as a,think_user as b where a.uid=b.uid and a.uid={$id} and a.type>0 order by time desc";
			$back = M()->query($sql);
		}else{
			$sql = "select * from think_feedback as a,think_user as b where a.uid=b.uid and a.uid={$id} and {$type} like '%{$key}%' and a.type>0 order by time desc";
			$back = M()->query($sql);
		}
	/* 	echo "<pre>";
		print_r($back);
		echo "</pre>"; */
		$this->assign("type",$type);
		$this->assign("key",$key);
		$this->assign("back",$back);
		$this->display();
	}
	
	
}